/**
 * Copyright (C) 2018 - 2020 https://github.com/LeeYan9
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bifrost.entity;

import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Lee
 * Create Class on 2018/8/9
 * @com.bifrost.entity
 * @wechat-mall
 */
@Data
@Entity
@Table(name = "PLAN_ITEM")
public class PlanItem extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(unique = true, nullable = false, name = "PLANITEM_ID")
    private Long planItemId;

    @Column(name = "HAS_LIMIT" , columnDefinition = "bit(1) DEFAULT NULL COMMENT '是否有限制'")
    private Boolean hasLimit = Boolean.FALSE;
    @Column(name = "LIMIT_QUANTITY" , columnDefinition = "int(11) DEFAULT NULL COMMENT '限制每人领取数量'")
    private Integer limitQuantity;
    @Column(name = "INVENTORY" , columnDefinition = "int(11) DEFAULT NULL COMMENT '库存'")
    private Integer inventory;
    @Column(name = "INVENTORY_AVAILABLE" , columnDefinition = "int(11) DEFAULT NULL COMMENT '可用库存'")
    private Integer inventoryAvailable;
    @Column(name = "SPECIFICATION" , columnDefinition = "varchar(20) DEFAULT NULL COMMENT '规格'")
    private String specification;
    @Column(name = "price" , columnDefinition = "decimal(10,2) DEFAULT NULL COMMENT '价格'")
    private BigDecimal price;
    @Column(name = "DESCRIPTION" , columnDefinition = "varchar(255) DEFAULT NULL COMMENT '详情'")
    private String description;
    @Column(name = "APPLY_SETTING" , columnDefinition = "varchar(255) DEFAULT NULL COMMENT '配置的key_[value]格式 用户选择项'" , length = 255)
    private String applySetting;
    @Column(name = "STORE_ID" , columnDefinition = "bigint(20) DEFAULT NULL COMMENT '门店id'" , nullable = false)
    private Long storeId;

    @OneToMany(mappedBy = "planItem")
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<PlanCusomer> planCusomers = new ArrayList<>();
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PLAN_ID", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT) , nullable = false)
    private Plan plan;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PRODUCT_ID", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT) , nullable = false)
    private Product product;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PRODUCT_SKU_ID", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT) , nullable = false)
    private ProductSku productSku;

}
